﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using QLChoDiaOc.Process;

namespace QLChoDiaOc.Forms
{
    /// <summary>
    /// Interaction logic for FormThayDoiQuyDinh.xaml
    /// </summary>
    public partial class FormThayDoiQuyDinh : Page
    {
        private InsertInfo _insertInfo = new InsertInfo();
        private SelectInfo _selectInfo = new SelectInfo();
        private OtherHandle _otherHandle = new OtherHandle();
        private UpdateInfo _updateInfo = new UpdateInfo();

        public FormThayDoiQuyDinh()
        {
            InitializeComponent();
            ShowQuyDinh();
        }

        void ShowQuyDinh()
        {
            txtSoNgayHenChupAnhToiDa.Text = _selectInfo.SelectThamSo("SoNgayHenChupAnhToiDa").ToString();
            txtSoThangCoGiaTri.Text = _selectInfo.SelectThamSo("SoThangCoGiaTri").ToString();
            txtSoToBuomToiThieu.Text = _selectInfo.SelectThamSo("SoToBuomToiThieu").ToString();
            txtSoTuToiDa.Text = _selectInfo.SelectThamSo("SoTuToiDa").ToString();
            txtTiLePhieuThuKeTiep.Text = _selectInfo.SelectThamSo("TiLePhieuThuKeTiep").ToString();
            txtTuoiToiThieu.Text = _selectInfo.SelectThamSo("TuoiToiThieu").ToString();
        }

        bool KiemTraNhap()
        {
            if (txtSoNgayHenChupAnhToiDa.Text == "" ||
                txtSoThangCoGiaTri.Text == "" ||
                txtSoToBuomToiThieu.Text == "" ||
                txtSoTuToiDa.Text == "" ||
                txtTiLePhieuThuKeTiep.Text == "" ||
                txtTuoiToiThieu.Text == "")
                return true;
            else
                return false;
        }

        private void btnSuaQuyDinh_Click(object sender, RoutedEventArgs e)
        {
            if (KiemTraNhap())
                MessageBox.Show("Chưa Nhập Đầy Đủ Thông Tin", "Thông Báo");
            else
            {
                _updateInfo.UpdateThamSo("SoNgayHenChupAnhToiDa", float.Parse(txtSoNgayHenChupAnhToiDa.Text));
                _updateInfo.UpdateThamSo("SoThangCoGiaTri", float.Parse(txtSoThangCoGiaTri.Text));
                _updateInfo.UpdateThamSo("SoToBuomToiThieu", float.Parse(txtSoToBuomToiThieu.Text));
                _updateInfo.UpdateThamSo("SoTuToiDa", float.Parse(txtSoTuToiDa.Text));
                _updateInfo.UpdateThamSo("TiLePhieuThuKeTiep", float.Parse(txtTiLePhieuThuKeTiep.Text));
                _updateInfo.UpdateThamSo("TuoiToiThieu", float.Parse(txtTuoiToiThieu.Text));
            }
        }

        private void txtSoNgayHenChupAnhToiDa_TextChanged(object sender, TextChangedEventArgs e)
        {
            _otherHandle.IsNumber(txtSoNgayHenChupAnhToiDa);
        }

        private void txtSoThangCoGiaTri_TextChanged(object sender, TextChangedEventArgs e)
        {
            _otherHandle.IsNumber(txtSoThangCoGiaTri);
        }

        private void txtSoToBuomToiThieu_TextChanged(object sender, TextChangedEventArgs e)
        {
            _otherHandle.IsNumber(txtSoToBuomToiThieu);
        }

        private void txtSoTuToiDa_TextChanged(object sender, TextChangedEventArgs e)
        {
            _otherHandle.IsNumber(txtSoTuToiDa);
        }

        private void txtTiLePhieuThuKeTiep_TextChanged(object sender, TextChangedEventArgs e)
        {
            _otherHandle.IsNumber(txtTiLePhieuThuKeTiep);
        }

        private void txtTuoiToiThieu_TextChanged(object sender, TextChangedEventArgs e)
        {
            _otherHandle.IsNumber(txtTuoiToiThieu);
        }
    }
}
